/**
 * datagrid - jQuery xui
 *
 * Licensed under the GPL:
 *   http://www.gnu.org/licenses/gpl.txt
 *
 * Copyright 2013 xjb [ beymy.en@gmail.com ]
 *
 * 依赖
 *   mask
 *	 pagination
 */
(function ($) {
    /**
     *设置大小
     */
    function setSize(target) {
        var grid = $.data(target, 'datagrid').grid;
        var opts = $.data(target, 'datagrid').options;

        if (opts.rownumbers) {
            $('.datagrid-body .datagrid-cell,.datagrid-body .datagrid-cell-rownumber', grid).addClass('datagrid-cell-height');
        }

        var gridWidth = opts.width;
        if (gridWidth == 'auto') {
            gridWidth = grid.width();
        } else {
            gridWidth -= (grid.outerWidth() - grid.width());
        }
        grid.width(gridWidth);

        var innerWidth = gridWidth;

        $('.datagrid-view', grid).width(innerWidth);
        $('.datagrid-view .datagrid-header', grid).width($('.datagrid-view', grid).width());
        $('.datagrid-view .datagrid-body', grid).width($('.datagrid-view', grid).width());

        var hh, hth;
        var header = $('.datagrid-view .datagrid-header', grid);
        var htable = $('.datagrid-htable', header);
        htable.css('height', null);
        header.css('height', null);
        //隐藏table的边框
        hh = header.outerHeight();
        hth = hh - $('.datagrid-toolbar', header).outerHeight();
        htable.height(hth);
        header._outerHeight(hh);

        if (opts.height == 'auto') {
            $('.datagrid-body', grid).height($('.datagrid-view .datagrid-body table', grid).height());
        } else {
            $('.datagrid-body', grid)._outerHeight(
                opts.height - $('.datagrid-header', grid).outerHeight(true) - $('.datagrid-title', grid).outerHeight(true) - $('.datagrid-pager', grid).outerHeight(true)
            );
        }
    }

    /**
     * 包裹<table>,返回{grid,columns}
     */
    function wrapGrid(target, rownumbers) {
        var grid = $(target).wrap('<div class="datagrid"></div>').parent();
        var columns = getColumns($('thead', target));

        grid.prepend('<div class="datagrid-view">' +
            '<div class="datagrid-header">' +
            '<div class="datagrid-header-inner"></div>' +
            '</div>' +
            '<div class="datagrid-body"></div>' +
            '<div class="datagrid-resize-proxy"></div>' +
            '</div>');

        $(target).hide();

        function getColumns(thead) {
            var columns = [];
            $('tr', thead).each(function () {
                var cols = [];
                $('th', this).each(function () {
                    var th = $(this);

                    var col = $.extend({
                        title: th.html()
                    }, $.parser.parseOptions(this, [
                        'align', 'width', {
                            rowspan: 'number',
                            colspan: 'number'
                        }
                    ]));

                    cols.push(col);
                });
                columns.push(cols);
            });

            return columns;
        }

        return {
            grid: grid,
            columns: columns
        };
    }

    /**
     *构建表头
     */
    function buildHeader(target) {
        var opts = $.data(target, 'datagrid').options;
        var grid = $.data(target, 'datagrid').grid;
        var columns = opts.columns;
        var header = ['<table border="0" cellspacing="0" cellpadding="0" class="datagrid-htable">'];
        for (var i = 0; i < columns.length; i++) {
            header.push('<tr class="datagrid-header-row">');
            var tr;
            if (i == 0 && opts.rownumbers) {　 //行号
                if (columns.length > 1) {
                    header.push('<td rowspan="' + columns.length + '"><div class="datagrid-cell-rownumber"></div></td>');
                } else {
                    header.push('<td class="datagrid-cell-rownumber"><div class="datagrid-cell-rownumber"></div></td>');
                }
            }
            var cols = columns[i];
            for (var j = 0; j < cols.length; j++) {
                var col = cols[j];
                header.push('<td');
                if (col.rowspan)
                    header.push(' rowspan="' + col.rowspan + '"');
                if (col.colspan)
                    header.push(' colspan="' + col.colspan + '"');
                if (col.field)
                    header.push(' field="' + col.field + '"');
                header.push('>');

                header.push('<div');
                if (col.width) {
                    header.push(' style="width:' + col.width + 'px;"');
                }

                if (col.checkbox) {
                    header.push(' class="datagrid-header-check">');
                    header.push('<input type="checkbox"/>');
                } else if (col.field) { //column
                    header.push(' class="datagrid-cell">');
                    header.push(col.title);
                } else { //group
                    header.push(' class="datagrid-cell-group">');
                    header.push(col.title);
                }
                header.push('</div>');
                header.push('</td>');
            }

            header.push('</tr>');
        }
        header.push('</table>');
        $('.datagrid-header-inner', grid).html(header.join(''));

        //工具栏

        if (opts.toolbar) {
            if ($.isArray(opts.toolbar)) {
                $('div.datagrid-toolbar', grid).remove();
                var tb = $('<div class="datagrid-toolbar"></div>').prependTo($('.datagrid-header', grid));
                for (var i = 0; i < opts.toolbar.length; i++) {
                    var btn = opts.toolbar[i];
                    if (btn == '-') {
                        $('<div class="datagrid-btn-separator"></div>').appendTo(tb);
                    } else {
                        var tool = $('<a href="javascript:void(0)"></a>').appendTo(tb);
                        tool[0].onclick = (btn.handler || function () {});
                        tool.linkbutton($.extend({}, btn, {
                            plain: true
                        }));
                    }
                }
            } else { //toolbar支持ID
                $(opts.toolbar).addClass("datagrid-toolbar").prependTo($('.datagrid-header', grid));
            }
        } else {
            $('div.datagrid-toolbar', grid).remove();
        }

        //标题
        $('.datagrid-title', grid).remove();
        if (opts.title) {
            grid.prepend('<div class="datagrid-title">' + opts.title + '</div>');
        }
    }

    /**
     *构建row
     */
    function buildRow(tr, fields, opts, i, row) {
        if (i % 2 && opts.striped) {
            tr.push('<tr datagrid-row-index="' + i + '" class="datagrid-row datagrid-row-alt">');
        } else {
            tr.push('<tr datagrid-row-index="' + i + '" class="datagrid-row">');
        }

        if (opts.rownumbers) {
            var rownumber = i + 1;
            if (opts.pagination) {
                rownumber += (opts.pageNumber - 1) * opts.pageSize;
            }
            tr.push('<td><div class="datagrid-cell-rownumber">' + rownumber + '</div></td>');
        }
        for (var j = 0; j < fields.length; j++) {
            var field = fields[j];
            var col = getColumnOption(opts.columns, field);
            if (col) {
                tr.push('<td field="' + field + '">');
                tr.push('<div ');

                if (col.width && !col.fit) {
                    tr.push('style="width:' + col.width + 'px;"');
                }

                if (col.checkbox) {
                    tr.push('class="datagrid-cell-check ');
                } else {
                    tr.push('class="datagrid-cell ');
                }
                tr.push('">');

                if (col.checkbox) {
                    tr.push('<input type="checkbox"/>');
                } else if (col.formatter) {
                    tr.push(col.formatter(row[field], row, i));
                } else {
                    tr.push(row[field]);
                }
                tr.push('</div>');
                tr.push('</td>');
            }
        }
        tr.push('</tr>');
    }

    /**
     *构建body
     */
    function buildBody(target, rows) {
        var opts = $.data(target, 'datagrid').options;
        var grid = $.data(target, 'datagrid').grid;
        var rownumbers = opts.rownumbers;
        var fields = getColumnFields(opts.columns);


        var body = ['<table border="0" cellspacing="0" cellpadding="0" class="datagrid-btable">'];
        for (var i = 0; i < rows.length; i++) {
            buildRow(body, fields, opts, i, rows[i]);
        }
        body.push('</table>');

        $('.datagrid-body', grid).html(body.join(''));

        if (opts.nowrap == false) {
            $('.datagrid-body .datagrid-cell', grid).css('word-break', 'break-all');
        }
    }

    /**
     *构建pagination
     */
    function buildPagination(target) {
        var state = $.data(target, 'datagrid');
        var opts = state.options;
        var grid = state.grid;

        $('.datagrid-pager', grid).remove(); //移除以前的分页
        if (opts.pagination) {
            var pager = $('<div class="datagrid-pager"></div>');
            $('.datagrid-view', grid).append(pager);
            pager.pagination({
                pageNumber: opts.pageNumber,
                pageSize: opts.pageSize,
                pageList: opts.pageList,
                onSelectPage: function (pageNum, pageSize) {
                    // 保存分页状态
                    opts.pageNumber = pageNum;
                    opts.pageSize = pageSize;

                    request(target); // 请求远程数据
                }
            });
            //opts.pageSize = pager.pagination('options').pageSize; // repare the pageSize value
        }
    }

    /**
     * 绑定事件
     */
    function bindEvents(target) {
        var opts = $.data(target, 'datagrid').options;
        var grid = $.data(target, 'datagrid').grid;
        var data = $.data(target, 'datagrid').data;
        //body事件
        $('.datagrid-body .datagrid-cell-check input[type="checkbox"]', grid).unbind('.datagrid').bind('click.datagrid', function (e) {
            e.stopPropagation();
        });


        $('.datagrid-body tr', grid).unbind('.datagrid').bind('mouseover.datagrid', function () {
            $(this).addClass('datagrid-row-over');
        }).bind('mouseout.datagrid', function () {
            $(this).removeClass('datagrid-row-over');
        }).bind('click.datagrid', function () {
            var index = $(this).attr('datagrid-row-index');
            if ($(this).hasClass('datagrid-row-selected')) {
                if (opts.singleSelect == false) {
                    unselectRow(target, index);
                }
            } else {
                selectRow(target, index);
            }

            if (opts.onClickRow) {
                opts.onClickRow.call(this, index, data.rows[index]);
            }
        }).bind('dblclick.datagrid', function () {
            var index = $(this).attr('datagrid-row-index');
            if (!$(this).hasClass('datagrid-row-selected')) { //双击选中当前行
                selectRow(target, index);
            }
            if (opts.onDblClickRow) {
                opts.onDblClickRow.call(this, index, data.rows[index]);
            }
        });


        //header事件
        $('.datagrid-header td:has(.datagrid-cell)', grid).unbind('.datagrid').bind('mouseover.datagrid', function () {
            $(this).addClass('datagrid-header-over');
        }).bind('mouseout.datagrid', function () {
            $(this).removeClass('datagrid-header-over');
        });

        $('.datagrid-header .datagrid-header-check input[type="checkbox"]', grid).unbind('.datagrid').bind('click.datagrid', function () {
            if ($(this).prop('checked')) {
                $('.datagrid-body .datagrid-cell-check input[type="checkbox"]', grid).prop('checked', true);
            } else {
                $('.datagrid-body .datagrid-cell-check input[type="checkbox"]', grid).prop('checked', false);
            }
        });

        $('.datagrid-header .datagrid-cell', grid).resizable({
            handles: ['e'],
            onStartResize: function (e) {
                $('.datagrid-resize-proxy', grid).css({
                    left: e.pageX - $(grid).offset().left - 1
                });
                $('.datagrid-resize-proxy', grid).css('display', 'block');
            },
            onResize: function (e) {
                $('.datagrid-resize-proxy', grid).css({
                    left: e.pageX - $(grid).offset().left - 1
                });
                return false;
            },
            onStopResize: function (e) {
                fixColumnSize(target, false, this);
                $('.datagrid-resize-proxy', grid).css('display', 'none');
            }
        });

        //滚动事件
        $('.datagrid-body', grid).scroll(function () {
            $('.datagrid-header', grid).scrollLeft($(this).scrollLeft());
        });
    }

    /**
     * 根据指定的单元格固定列宽
     */
    function fixColumnSize(target, fit, cell) {
        var grid = $.data(target, 'datagrid').grid;
        var opts = $.data(target, 'datagrid').options;

        if (cell) {
            fix(cell);
        } else {
            $('.datagrid-header .datagrid-cell', grid).each(function () {
                fix(this);
            });
        }

        function fix(cell) {
            var headerCell = $(cell);
            if (headerCell.width() == 0) return;

            var fieldName = headerCell.parent().attr('field');
            var col = getColumnOption(opts.columns, fieldName);
            var cells = $('.datagrid-body td[field="' + fieldName + '"] .datagrid-cell', grid);

            if (col.fit & fit) {
                var width = headerCell.width();
                cells.each(function () {
                    width = Math.max(width, $(this).width());
                });
                cells.width(width);
                headerCell.width(width);
            } else {
                cells.width(headerCell.width());
            }
            col.width = headerCell.width();
        }
    }

    /**
     * 根据field获取对应field的选项
     */
    function getColumnOption(columns, field) {
        if (columns) {
            for (var i = 0; i < columns.length; i++) {
                var cols = columns[i];
                for (var j = 0; j < cols.length; j++) {
                    var col = cols[j];
                    if (col.field == field) {
                        return col;
                    }
                }
            }
        }
        return null;
    }

    /**
     * 获取fields
     */
    function getColumnFields(columns) {
        if (columns.length == 0) return [];

        function getFields(ridx, cidx, count) {
            var fields = [];
            while (fields.length < count) {
                var col = columns[ridx][cidx];
                if (col.colspan && col.colspan > 1) {
                    var ff = getFields(ridx + 1, getSubColIndex(ridx, cidx), col.colspan);
                    fields = fields.concat(ff);
                } else if (col.field) {
                    fields.push(col.field);
                }
                cidx++;
            }

            return fields;
        }

        function getSubColIndex(ridx, cidx) {
            var index = 0;
            for (var i = 0; i < cidx; i++) {
                var colspan = columns[ridx][i].colspan || 1;
                if (colspan > 1) {
                    index += colspan;
                }
            }
            return index;
        }

        var fields = [];
        for (var i = 0; i < columns[0].length; i++) {
            var col = columns[0][i];
            if (col.colspan && col.colspan > 1) {
                var ff = getFields(1, getSubColIndex(0, i), col.colspan);
                fields = fields.concat(ff);
            } else if (col.field) {
                fields.push(col.field);
            }
        }

        return fields;
    }

    /**
     * 获取colspan
     */
    function getColumnColspan(columns) {
        var column = columns[0];
        var colspan = 0;
        for (var i = 0; i < column.length; i++) {
            colspan += (column[i].colspan || 1);
        }
        return colspan;
    }

    /**
     * 加载数据
     */
    function loadData(target, data) {
        var state = $.data(target, 'datagrid');
        var grid = state.grid;
        //数组数据处理
        if ($.isArray(data)) {
            data = {
                rows: data,
                total: data.length
            }
        } else {
            data.total = parseInt(data.total); //防止total是字符串
        }
        buildBody(target, data.rows);
        state.data = data;
        state.insertedRows = [];
        state.deletedRows = [];

        $('.datagrid-pager', grid).pagination({
            total: data.total
        });
        fixColumnSize(target, true);
        setSize(target);
        bindEvents(target);
    }

    function getRowIndex(target, row) {
        var state = $.data(target, 'datagrid');
        var rows = state.data.rows;

        for (var i = 0, len = rows.length; i < len; i++) {
            if (rows[i] == row) {
                return i;
            }
        }
        return -1;
    };

    /**
     * 获取checked记录
     */
    function getCheckedRows(target) {
        var state = $.data(target, 'datagrid');
        var opts = state.options;
        var grid = state.grid;
        var data = state.data;

        var rows = [];
        $('.datagrid-body tr:has(.datagrid-cell-check>input[type="checkbox"]:checked)', grid).each(function () {
            var index = parseInt($(this).attr('datagrid-row-index'));
            if (data.rows[index]) {
                rows.push(data.rows[index]);
            }
        });
        return rows;
    };

    /**
     * 获取selected记录
     */
    function getSelectedRows(target) {
        var state = $.data(target, 'datagrid');
        var opts = state.options;
        var grid = state.grid;
        var data = state.data;

        var rows = [];
        $('.datagrid-body tr.datagrid-row-selected', grid).each(function () {
            var index = parseInt($(this).attr('datagrid-row-index'));
            if (data.rows[index]) {
                rows.push(data.rows[index]);
            }
        });
        return rows;
    }

    /**
     * 清除全部选中记录
     */
    function clearSelections(target) {
        var grid = $.data(target, 'datagrid').grid;
        $('.datagrid-body tr.datagrid-row-selected', grid).removeClass('datagrid-row-selected');
        $('.datagrid-body .datagrid-cell-check input[type="checkbox"]', grid).prop('checked', false);
    }

    /**
     * 根据索引选中记录,索引从这0开始
     */
    function selectRow(target, index) {
        var opts = $.data(target, 'datagrid').options;
        var grid = $.data(target, 'datagrid').grid;
        var data = $.data(target, 'datagrid').data;

        var tr = $('.datagrid-body tr[datagrid-row-index="' + index + '"]', grid);
        var ck = $('.datagrid-body tr[datagrid-row-index="' + index + '"] .datagrid-cell-check input[type="checkbox"]', grid);
        if (opts.singleSelect == true) {
            clearSelections(target);
        }
        tr.addClass('datagrid-row-selected');
        ck.prop('checked', true);

        opts.onSelect.call(target, index, data.rows[index]);
    }

    /**
     * 根据索引取消选中记录,索引从这0开始
     */
    function unselectRow(target, index) {
        var opts = $.data(target, 'datagrid').options;
        var grid = $.data(target, 'datagrid').grid;

        var tr = $('.datagrid-body tr[datagrid-row-index="' + index + '"]', grid);
        var ck = $('.datagrid-body tr[datagrid-row-index="' + index + '"] .datagrid-cell-check input[type="checkbox"]', grid);
        tr.removeClass('datagrid-row-selected');
        ck.prop('checked', false);

        var row = $.data(target, 'datagrid').data.rows[index];
        opts.onUnselect.call(target, index, row);
    }

    function insertRow(target, index, row) {
        var state = $.data(target, 'datagrid');
        var opts = state.options;
        var grid = state.grid;
        var data = state.data;
        var insertedRows = state.insertedRows;
        var fields = getColumnFields(opts.columns);

        if (index == undefined || index == null) {
            index = data.rows.length;
        }
        if (index > data.rows.length) {
            index = data.rows.length;
        }

        var tr = [];
        buildRow(tr, fields, opts, index, row);
        $('.datagrid-body .datagrid-btable', grid).append(tr.join(''));

        data.total += 1;
        data.rows.splice(index, 0, row);

        insertedRows.push(row);
        $('.datagrid-pager', grid).pagination({
            total: data.total
        });

        fixColumnSize(target);
        bindEvents(target);
    };

    function appendRow(target, row) {
        insertRow(target, null, row);
    };

    /**
     * 根据索引删除记录,索引从这0开始
     */
    function deleteRow(target, index) {
        var state = $.data(target, 'datagrid');
        var opts = state.options;
        var grid = state.grid;
        var data = state.data;
        var insertedRows = state.insertedRows;
        var deletedRows = state.deletedRows;

        function refreshView() {
            for (var i = index + 1, len = data.rows.length; i < len; i++) {
                var tr = $('.datagrid-body tr[datagrid-row-index="' + i + '"]', grid);
                tr.attr('datagrid-row-index', i - 1);
                if (opts.rownumbers) {
                    var rownum = i;
                    if (opts.pagination) {
                        rownum += (opts.pageNumber - 1) * opts.pageSize;
                    }
                    tr.find('div.datagrid-cell-rownumber').html(rownum);
                }
                if (opts.striped) {
                    tr.removeClass('datagrid-row-alt').addClass((i - 1) % 2 ? 'datagrid-row-alt' : '');
                }
            }
        };
        //删除行tr
        $('.datagrid-body tr[datagrid-row-index="' + index + '"]', grid).remove();
        //刷新view
        refreshView();
        //调整高度
        if (opts.height == 'auto') {
            setSize(target);
        }
        //删除数据
        var t = $.inArray(data.rows[index], insertedRows);
        if (t >= 0) {
            insertedRows.splice(t, 1);
        } else {
            deletedRows.push(data.rows[index]);
        }
        data.total -= 1;
        data.rows.splice(index, 1);
    }

    /**
     * 获取变更数据,type可以为inserted,deleted
     */
    function getChanges(target, type) {
        var state = $.data(target, 'datagrid');
        var insertedRows = state.insertedRows;
        var deletedRows = state.deletedRows;
        var rows = [];
        if (!type) {
            rows = rows.concat(insertedRows);
            rows = rows.concat(deletedRows);
        } else if (type == 'inserted') {
            rows = insertedRows;
        } else if (type == 'deleted') {
            rows = deletedRows;
        }
        return rows;
    }

    /**
     * 请求远程数据
     */
    function request(target) {
        var state = $.data(target, 'datagrid');
        var opts = state.options;
        var grid = state.grid;

        if (!opts.url) {
            return false;
        }

        var param = $.extend({}, opts.queryParams);
        if (opts.pagination) {
            $.extend(param, {
                page: opts.pageNumber,
                rows: opts.pageSize
            });
        }
        $('.datagrid-pager', grid).pagination({
            loading: true
        });
        $('.datagrid-view', grid).css('position', 'relative').mask();
        $.ajax({
            type: opts.method,
            url: opts.url,
            data: param,
            dataType: 'json',
            success: function (data) {
                $('.datagrid-pager', grid).pagination({
                    loading: false
                });
                $('.datagrid-view', grid).css('position', '').mask('destroy');
                loadData(target, data);
                if (opts.onLoadSuccess) {
                    opts.onLoadSuccess.apply(this, arguments);
                }
            },
            error: function () {
                $('.datagrid-pager', grid).pagination({
                    loading: false
                });
                $('.datagrid-view', grid).css('position', '').mask('destroy');
                if (opts.onLoadError) {
                    opts.onLoadError.apply(this, arguments);
                }
            }
        });
    }

    $.fn.datagrid = function (options, param) {
        if (typeof options == 'string') {
            return $.fn.datagrid.methods[options](this, param);
        }

        options = options || {};

        return this.each(function () {
            var state = $.data(this, 'datagrid');
            var opts;
            if (state) {
                opts = $.extend(state.options, options);

                if ($.inObject(['title', 'toolbar', 'columns'], options)) {
                    buildHeader(this);
                }

                if ($.inObject(['pageNumber', 'pageSize', 'pageList'], options)) {
                    buildPagination(this);
                }
            } else {
                opts = $.extend({}, $.fn.datagrid.defaults, $.fn.datagrid.parseOptions(this), options);

                var wrapResult = wrapGrid(this, opts.rownumbers);
                if (!opts.columns) {
                    opts.columns = wrapResult.columns;
                }
                $.data(this, 'datagrid', {
                    options: opts,
                    grid: wrapResult.grid,
                    data: {
                        total: 0,
                        rows: []
                    },
                    originalRows: [],
                    insertedRows: [],
                    deletedRows: []
                });
                buildHeader(this);
                buildPagination(this);
                setSize(this);
            }

            if (opts.data) {
                loadData(this, opts.data);
            }

            if (opts.url) {
                request(this);
            }

            bindEvents(this);
        });
    };

    $.fn.datagrid.methods = {
        options: function (jq) {
            return $.data(jq[0], 'datagrid').options;
        },
        reload: function (jq) {
            return jq.each(function () {
                request(this);
            });
        },
        loadData: function (jq, param) {
            return jq.each(function () {
                loadData(this, param);
            });
        },
        getData: function (jq) {
            return $.data(jq[0], "datagrid").data;
        },
        getRows: function (jq) {
            return $.data(jq[0], "datagrid").data.rows;
        },
        getRowIndex: function (jq, id) {
            return getRowIndex(jq[0], id);
        },
        getChecked: function (jq) {
            return getCheckedRows(jq[0]);
        },
        getSelected: function (jq) {
            var rows = getSelectedRows(jq[0]);
            return rows.length > 0 ? rows[0] : null;
        },
        getSelections: function (jq) {
            return getSelectedRows(jq[0]);
        },
        clearSelections: function (jq) {
            return jq.each(function () {
                clearSelections(this);
            });
        },
        selectRow: function (jq, param) {
            return jq.each(function () {
                selectRow(this, param);
            });
        },
        unselectRow: function (jq, param) {
            return jq.each(function () {
                unselectRow(this, param);
            });
        },
        appendRow: function (jq, param) {
            return jq.each(function () {
                appendRow(this, param);
            });
        },
        insertRow: function (jq, param) {
            return jq.each(function () {
                insertRow(this, param.index, param.row);
            });
        },
        deleteRow: function (jq, param) {
            return jq.each(function () {
                deleteRow(this, param);
            });
        },
        getChanges: function (jq, param) {
            return getChanges(jq[0], param);
        }
    };

    $.fn.datagrid.parseOptions = function (target) {
        return $.extend({}, $.parser.parseOptions(target, [
            'width', 'height', 'title'
        ]));
    };

    $.fn.datagrid.defaults = {
        title: '',
        iconCls: null,
        border: true,
        width: 'auto',
        height: 'auto',
        columns: null,
        toolbar: null, //工具栏
        striped: false, //条纹
        method: 'post',
        nowrap: true, //不换行
        url: null,
        loadMsg: '正在处理，请稍待。。。',
        pagination: false,
        rownumbers: false,
        singleSelect: true,
        pageNumber: 1,
        pageSize: 10,
        pageList: [10, 20, 30, 40, 50],
        queryParams: {},

        onLoadSuccess: function () {},
        onLoadError: function () {},
        onClickRow: function (rowIndex, rowData) {},
        onDblClickRow: function (rowIndex, rowData) {},
        onSelect: function (rowIndex, rowData) {},
        onUnselect: function (rowIndex, rowData) {}
    };
})(jQuery);